package com.cookie.libnetwork;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.lang.reflect.Type;

/**
 * 项目名:    CookieJoke
 * 包名:      com.cookie.libnetwork
 * 文件名:    JsonConvert
 * 创建者:    cookie
 * 创建时间:   2020/2/29 0:25
 * 描述:      TODO
 */

public class JsonConvert implements Convert {


    @Override
    public Object Convert(String response, Type type) {
        JSONObject jsonObject = JSON.parseObject(response);
        JSONObject data = jsonObject.getJSONObject("data");
        if (data!=null){
            Object data1 = data.get("data");
            return  JSON.parseObject(data1.toString(),type);
        }
        return null;
    }

    @Override
    public Object Convert(String response, Class claz) {
        JSONObject jsonObject = JSON.parseObject(response);
        JSONObject data = jsonObject.getJSONObject("data");
        if (data!=null){
            Object data1 = data.get("data");
            return  JSON.parseObject(data1.toString(),claz);
        }
        return null;
    }
}
